package com.jyx.learning.service;

import com.jyx.framework.domain.course.TeachplanMediaPub;
import com.jyx.framework.domain.learning.responses.GetMediaResult;
import com.jyx.framework.domain.learning.responses.LearningCode;
import com.jyx.framework.exception.ExceptionCast;
import com.jyx.framework.model.response.CommonCode;
import com.jyx.learning.client.CourseSearchClient;
import com.jyx.learning.dao.TeachplanMediaPubRepository;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LearningService {
    @Autowired
    CourseSearchClient courseSearchClient;
    @Autowired
    TeachplanMediaPubRepository teachplanMediaPubRepository;

    public GetMediaResult getMedia(String courseId,String teachplanId){
        //TeachplanMediaPub teachplanMediaPub = courseSearchClient.getMedia(teachplanId);
        TeachplanMediaPub teachplanMediaPub = teachplanMediaPubRepository.findByCourseIdAndAndTeachplanId(courseId, teachplanId);
        if(teachplanMediaPub == null || StringUtils.isEmpty(teachplanMediaPub.getMediaUrl())){
            //return new GetMediaResult(LearningCode.LEARNING_GETMEDIA_ERROR,null);
            System.out.println("课程发布媒体资料为空！");
            ExceptionCast.cast(LearningCode.LEARNING_GETMEDIA_ERROR);
        }
        return new GetMediaResult(CommonCode.SUCCESS, teachplanMediaPub.getMediaUrl());
    }


}
